<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h2>local</h2>
    <button onclick="savedata()">点我保存</button>
    <button onclick="readdata()">点我读取</button>
    <button onclick="deletedata()">点我删除</button>
    <button onclick="deleteALLdata()">点我</button>
    <script type="text/javascript">
        let p = { name: '张三', age: 18 }
        function savedata() {
            sessionStorage.setItem('msg', 'hello')
            sessionStorage.setItem('person',JSON.stringify(p))
        }
        function readdata() {
            console.log(sessionStorage.getItem('msg'))
            const result = sessionStorage.getItem('person')
            console.log(JSON.parse(result))
        }
        function deletedata() {
            sessionStorage.removeItem('msg2')
        }
        function deleteALLdata() {
            sessionStorage.clear('msg')

        }
    </script>
</body>

</html>